package com.itboy.mall.wms.warepurchasedetail.controller;

import java.util.List;
import java.util.Arrays;

import com.itboy.mall.wms.warepurchasedetail.bo.PurchaseDetailBo;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.itboy.common.annotation.RepeatSubmit;
import com.itboy.common.annotation.Log;
import com.itboy.common.core.controller.BaseController;
import com.itboy.common.core.domain.AjaxResult;
import com.itboy.common.enums.BusinessType;
import com.itboy.mall.wms.warepurchasedetail.vo.MallWarePurchaseDetailVo;
import com.itboy.mall.wms.warepurchasedetail.bo.MallWarePurchaseDetailQueryBo;
import com.itboy.mall.wms.warepurchasedetail.bo.MallWarePurchaseDetailAddBo;
import com.itboy.mall.wms.warepurchasedetail.bo.MallWarePurchaseDetailEditBo;
import com.itboy.mall.wms.warepurchasedetail.service.IMallWarePurchaseDetailService;
import com.itboy.common.utils.poi.ExcelUtil;
import com.itboy.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 采购需求
Controller
 *
 * @author itboy
 * @date 2021-08-10
 */
@Validated
@Api(value = "采购需求控制器", tags = {"采购需求管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/mall/warePurchaseDetail")
public class MallWarePurchaseDetailController extends BaseController {

    private final IMallWarePurchaseDetailService iMallWarePurchaseDetailService;

    /**
     * 查询采购需求
列表
     */
    @ApiOperation("查询采购需求列表")
    @PreAuthorize("@ss.hasPermi('mall:warePurchaseDetail:list')")
    @GetMapping("/list")
    public TableDataInfo<MallWarePurchaseDetailVo> list(@Validated MallWarePurchaseDetailQueryBo bo) {
        return iMallWarePurchaseDetailService.queryPageList(bo);
    }

    /**
     * 导出采购需求列表
     */
    @ApiOperation("导出采购需求列表")
    @PreAuthorize("@ss.hasPermi('mall:warePurchaseDetail:export')")
    @Log(title = "采购需求", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<MallWarePurchaseDetailVo> export(@Validated MallWarePurchaseDetailQueryBo bo) {
        List<MallWarePurchaseDetailVo> list = iMallWarePurchaseDetailService.queryList(bo);
        ExcelUtil<MallWarePurchaseDetailVo> util = new ExcelUtil<MallWarePurchaseDetailVo>(MallWarePurchaseDetailVo.class);
        return util.exportExcel(list, "采购需求");
    }

    /**
     * 获取采购需求详细信息
     */
    @ApiOperation("获取采购需求详细信息")
    @PreAuthorize("@ss.hasPermi('mall:warePurchaseDetail:query')")
    @GetMapping("/{id}")
    public AjaxResult<MallWarePurchaseDetailVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iMallWarePurchaseDetailService.queryById(id));
    }

    /**
     * 新增采购需求
     */
    @ApiOperation("新增采购需求")
    @PreAuthorize("@ss.hasPermi('mall:warePurchaseDetail:add')")
    @Log(title = "采购需求", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody MallWarePurchaseDetailAddBo bo) {
        return toAjax(iMallWarePurchaseDetailService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改采购需求
     */
    @ApiOperation("修改采购需求")
    @PreAuthorize("@ss.hasPermi('mall:warePurchaseDetail:edit')")
    @Log(title = "采购需求", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody MallWarePurchaseDetailEditBo bo) {
        return toAjax(iMallWarePurchaseDetailService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除采购需求

     */
    @ApiOperation("删除采购需求")
    @PreAuthorize("@ss.hasPermi('mall:warePurchaseDetail:remove')")
    @Log(title = "采购需求" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iMallWarePurchaseDetailService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }

	/**
	 * 合并分配采购单
	 */
	@ApiOperation("合并分配采购单")
	@Log(title = "合并分配采购单", businessType = BusinessType.UPDATE)
	@RepeatSubmit
	@PostMapping("/mergeAssignPurchaseOrder")
	public AjaxResult<Void> mergeAssignPurchaseOrder(@Validated @RequestBody PurchaseDetailBo bo) {
		return toAjax(iMallWarePurchaseDetailService.mergeAssignPurchaseOrder(bo) ? 1 : 0);
	}


}
